#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@file: thread.py
@author: lyndon
@time: Created on 2021-01-21 9:01
@env: Python
@desc:
@ref:
@blog:
"""

import time
from threading import Semaphore, Thread


def add(sem: Semaphore, a, b):
    sem.acquire()
    time.sleep(1)
    d = a + b
    print(str(d) + "\n")
    sem.release()


if __name__ == '__main__':

    sem = Semaphore(4)

    for i in range(10):
        t = Thread(target=add, args=(sem, i, i+5))
        t.start()
